package cn.edu.tsinghua.ie.ieFunds.service;

import cn.edu.tsinghua.ie.ieFunds.bean.base.Stock;
import cn.edu.tsinghua.ie.ieFunds.repository.StockRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
public class StockService {

    @Autowired
    private StockRepository stockRepository;

    public void save(Stock stock) {
        stockRepository.save(stock);
    }

    @Transactional
    public Page<Stock> getPage(String stockName, Pageable pageable) {
        return stockRepository.findAllByName(stockName, pageable);
    }

    @Transactional
    public Page<Stock> getDistinctPage(Pageable pageable) {
        return stockRepository.getDistinctPage(pageable);
    }

    @Transactional
    public List<Stock> getDistinctList() {
        return stockRepository.getDistinctList();
    }
}
